require(["core", "bus_permission"], function(jSouper, bus_permission) {
	window._pers_item_childs_to_keys = function(childs) {
		var keys = []
		jSouper.forEach(childs, function(child) {
			keys.push.apply(keys, bus_permission.hash_to_keys(child.hash));
		});
		return keys
	};
	window._pers_childs_in_keys = function(keys, hash) {
		if (keys && keys.length) {
			var _child_keys = bus_permission.hash_to_keys(hash);
			return !!jSouper.filter(_child_keys, function(key) {
				return jSouper.indexOf(keys, key) !== -1
			}).length
		}
	};
	// App.set("keys",[])
	App.set("renderable", bus_permission.tree_to_renderable(bus_permission.default_pers));
	App.set("$Event.toggle_checkbox", function(e, vm) {
		var keys = App.get("keys") || [];
		var _child_keys = bus_permission.hash_to_keys(vm.get("hash"));
		if (this.checked) {
			keys.push.apply(keys, _child_keys)
		} else {
			jSouper.forEach(_child_keys, function(key) {
				keys = jSouper.$.rm(keys, key)
			});
		}
		App.set("keys", keys);
	});
});

// function a(a1, a2) {
// 	console.log(this, arguments);
// }

// a.apply({
// 	name: "title"
// }, [1, 2])